<?php
namespace App\Http\Controllers\Api;

use App\Http\Controllers\Controller;
use App\Services\Qiniuyun;
use Illuminate\Http\Request;

class PublicsController extends Controller
{
    public function upImages(Request $request){
        if($request->hasFile('preview')){
            $client = new Qiniuyun();
            $file = $request->preview;
            $file_name = md5(time()).'.'.$file->getClientOriginalExtension();
            $error = $client->upFile($file_name,$file->getRealPath());

            if($error){
                $this->code = 1;
                $this->msg = $error;
                return $this->json();
            }
            $this->data['url'] = Qiniuyun::getFile($file_name);
            return $this->json();
        }
        $this->code = 1;
        $this->msg = '请上传文件';
        return $this->json();
    }

}
